package com.dt76.smallloanbackendservice.controller.afterloan;


import com.dt76.smallloanbackendservice.pojo.afterloan.RepaymentCommitInfo;
import com.dt76.smallloanbackendservice.pojo.afterloan.RepaymentInfo;
import com.dt76.smallloanbackendservice.pojo.afterloan.RepaymentQualification;
import com.dt76.smallloanbackendservice.service.afterloan.RepaymentService;
import com.dt76.smallloanbackendservice.utils.PageResult;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class RepaymentController {

    private final RepaymentService repaymentService;

    public RepaymentController(RepaymentService repaymentService) {
        this.repaymentService = repaymentService;
    }
    
    @PostMapping("/repayment/getPageList")
    public PageResult getPageList(@RequestBody RepaymentQualification q, Integer page, Integer size) {
        return repaymentService.qryAll(page, size, q);
    }

    @RequestMapping("/repayment/getById")
    public List<RepaymentInfo> getById(Integer id) {
        return repaymentService.getById(id);
    }

    @PostMapping("/repayment/commitRepaymentConfirm")
    public Map<String, Object> commitRepaymentConfirm(@RequestBody RepaymentCommitInfo q, Integer repaymentId, Integer loanId) {
        Map<String,Object> map = new HashMap<>();
        map.put("res",repaymentService.modifyCommitInfo(repaymentId, q));
        map.put("list",repaymentService.getById(loanId));
        return map;
    }

}
